package com.d.common.utils;

import io.swagger.annotations.ApiModelProperty;

import java.util.Map;

public class RT<T> {
    @ApiModelProperty("错误描述")
    private String msg;
    @ApiModelProperty("状态码 200成功、500错误")
    private int code;
    private T result;

    public static RT unlogin() {
        return error(1, "用户未登录");
    }

    public static RT badArgument() {
        return error(1, "参数错误");
    }

    public static RT badArgumentValue() {
        return error(1, "参数值错误");
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public RT() {
        this.code = 200;
        this.msg = "操作成功";
    }
    public RT(int code, String msg, T result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public RT(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static RT error() {
        return error(1, "操作失败");
    }

    public static RT error(String msg) {
        return error(500, msg);
    }

    public static RT error(int code, String msg) {
        return new RT(code, msg);
    }

    public static RT ok(String msg) {
        return new RT(200, msg);
    }

    public static RT ok(Map<String, Object> map) {
        return new RT(200, "操作成功", map);
    }

    public static RT ok(Object o) {
        return new RT(200, "操作成功", o);
    }

    public static RT ok() {
        return new RT();
    }

    public static RT error(String msg, Object o) {
        return new RT(500, msg, o);
    }
}
